package cn.tedu.ivos2.dictoption.controller;

import cn.tedu.ivos2.base.response.JsonResult;
import cn.tedu.ivos2.dictoption.pojo.dto.DictOptionQuery;
import cn.tedu.ivos2.dictoption.pojo.dto.DictOptionSaveParam;
import cn.tedu.ivos2.dictoption.pojo.vo.DictOptionVO;
import cn.tedu.ivos2.dictoption.service.DictOptionService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/v1/dictoption/")
public class DictOptionController {
    @Autowired
    private DictOptionService dictOptionService;

    @GetMapping("select")
    public JsonResult selectDictOption(DictOptionQuery dictOptionQuery) {
        log.debug("C1-查询参数:{}",dictOptionQuery);
        List<DictOptionVO>dictOptionVOList=dictOptionService.select(dictOptionQuery);
        log.debug("C1-查询结果:{}",dictOptionVOList);
        return JsonResult.ok(dictOptionVOList);
    }

    @PostMapping("save")
    public JsonResult saveDictOption(DictOptionSaveParam dictOptionSaveParam){
        log.debug("C2-保存字典项数据:{}",dictOptionSaveParam);
        dictOptionService.save(dictOptionSaveParam);
        return JsonResult.ok();
    }

    @PostMapping("delete/{id}")
    public JsonResult deleteDictOption(@PathVariable Long id){
        log.debug("C3-删除字典的id:{}",id);
        dictOptionService.delete(id);
        return JsonResult.ok();
    }
}
